package br.com.tecnove.random.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import br.com.tecnove.random.android.util.AnimationUtil;
import br.com.tecnove.random.android.util.RandomGenerator;

public class StringActivity extends Activity implements View.OnClickListener {

	private Button stringButton;
	private EditText stringText;
	private TextView txtLastRange;
	private ScrollView view;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.stringlayout);
		stringButton = (Button) findViewById(R.id.stringButton);
		stringText = (EditText) findViewById(R.id.editTextString);
		txtLastRange = (TextView) findViewById(R.id.txtLastRange);
		view = (ScrollView) findViewById(R.id.viewRangeScrollInside);

		stringButton.setOnClickListener(this);
	}

	public void onClick(View v) {
		String randomedValue;
		if (v.getId() == R.id.stringButton) {
			final String inputValue = stringText.getText().toString();
			if (("").equals(stringText)){
				Toast.makeText(this, getString(R.string.badInputRange), Toast.LENGTH_LONG).show();
				Log.e("BadInput", "Bad input at stringActivity: inputValue(" + inputValue +")");
				return;
			} else {
				randomedValue = String.valueOf(RandomGenerator.generateFromString(inputValue));
				AnimationUtil.animateTextView(randomedValue, view, txtLastRange);
			}
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.appdefaultmenu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return ContextMenu.itemClicked(item, this);
	}
}
